<?php
class ibodyModel extends model
{
	/**
	 * 解析全能框
	 * @param string $input：#(邮件|工作|待办|知识|记事)[(空格)@某人][(空格)[主题文字]]   结构的串
	 * 						例：#邮件 @chenyan 整理代码
	 * @return 数组：array('type' => (mail,work,todo,know,note),
	 * 					  'relate_user_id' => (0|用户ID),
	 *                    'relate_user_name' => (''|用户名),
	 *                    'subject' => (主题文字|''))
	 */
	public function parse_super_box($input){
		if(substr($input,0,1)!='#') return -1;//输入格式不正确
		$arr = explode(" ",$input);
		$arr_count = count($arr);
		if($arr_count==0) return -1;//输入格式不正确
		//获取 做什么
		$type='mail';
		switch(substr($arr[0],1)){
			case '邮件': $type='mail' ;break;
			case '工作': $type='work' ;break;
			case '待办': $type='todo' ;break;
			case '知识': $type='know' ;break;
			case '记事': $type='note' ;break;
			default: 	 $type='mail' ;break;
		}
		//获取用户信息以及主题
		$relate_user_id=0;
		$relate_user_name='';
		$subject='';
		if($arr_count>1){
			if(substr($arr[1],0,1)=='@'){
				$relate_user_name = substr($arr[1],1);
				$user = DB::fetchOne("SELECT * FROM ".DB::table('user')." where username='$relate_user_name'");
				if(count($user)==0) return -2;//用户不存在
				$relate_user_id = $user['user_id'];
				if(!empty($arr[2]))
					$subject = $arr[2];
			}else{
				$subject = $arr[1];
			}
		}
		
		return array('type' =>$type,'relate_user_id'=>$relate_user_id,
					'relate_user_name'=>$relate_user_name,'subject'=>$subject);
	}
}

?>